package com.haierp.task;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.haierp.exception.InventoryException;
import com.haierp.model.ErpOrder;
import com.haierp.service.IErpOrderService;
import com.haierp.util.BizResult;

/**
 * 扫描未备货完成的订单自动匹配
 * 
 * @author liuhui
 *
 */
@Component
public class AutoLockInventoryTask {
	
	@Autowired
	private IErpOrderService erpOrderService;
	
//	@Scheduled(cron = "0 0/1 * * * ?")
	public void run(){
		System.out.println(">>>>>>>>>> AutoLockInventoryTask start >>>>>>>>>>>>>>>");
		List<ErpOrder> erpOrders = erpOrderService.queryUnStockUpErpOrders(null);
		System.out.println("erpOrders size :" + erpOrders.size());
		for (ErpOrder erpOrder : erpOrders) {
			try {
				BizResult bizResult = erpOrderService.lockErpOrder(erpOrder);
// 				System.out.println("orderid:"+erpOrder.getId() + ", StockUpStatus : "+ orderStockupStatus);
				if(!bizResult.isSuccess()){
					System.out.println(bizResult.getMsg()+" orderid:"+erpOrder.getId() + ", StockUpStatus : "+ erpOrder.getStockStatus());
				}
				System.out.println("orderid:"+erpOrder.getId() + ", StockUpStatus : "+ erpOrder.getStockStatus());
			} catch (InventoryException e) {
				e.printStackTrace();
				System.out.println("LOCKORDER ERROR orderid:"+erpOrder.getId() + ", StockUpStatus : "+ erpOrder.getStockStatus()+e.getMessage());
			}catch(Exception ex){
				ex.printStackTrace();
				System.out.println("LOCKORDER ERROR orderid:"+erpOrder.getId() + ", StockUpStatus : "+ erpOrder.getStockStatus());
			}
		}
		
		System.out.println(">>>>>>>>>> AutoLockInventoryTask end >>>>>>>>>>>>>>>");
	}
}
